<?php

namespace App\Http\Controllers\Shop\Product;

use App\Http\Controllers\ShopController;
use App\Models\Product\Type as TypeModel;
use App\Models\Business\Business as BusinessModel;
use App\Models\Product\Product as ProductModel;
use App\Models\Business\Collection as CollectionModel;
use Illuminate\Support\Facades\Validator;

class TypeController extends ShopController
{
    public function index()
    {
        $TypeData = TypeModel::orderBy('weigh','desc')->get();
        // dd($TypeData);
        if($TypeData){
            return $this->success('查询成功',$TypeData);
        }else{
            return $this->error('查询失败',[]);
        }
        // return $TypeData;
    }

    public function product()
    {
        $typeid = request('typeid',0);
        // dd($proid);
        if($typeid===0){
            $TypeData = ProductModel::orderBy('createtime','desc')->get();
            $count = ProductModel::count();
        }else{
            $TypeData = ProductModel::where(['typeid'=>$typeid])->orderBy('createtime','desc')->get();
            $count = ProductModel::where(['typeid'=>$typeid])->count();
        }
        
        $data = [
            'list' => $TypeData,
            'count' => $count
        ];

        // dd($TypeData);
        if($TypeData){
            return $this->success('查询成功',$data);
        }else{
            return $this->error('查询失败',[]);
        }
    }
}